﻿using System;
using System.Collections.Generic;
using UnityEngine;
using System.Reflection;



public class NetManager:MonoBehaviour
{


    HandlerManager mgr;
    void Start()
    {
        mgr = RootManager.GetManager<HandlerManager>();
        SocketHelper.GetInstance();
    }

    // Update is called once per frame
    void Update()
    {
        byte[] bytes = SocketHelper.GetInstance().FetchPack();
        if (bytes != null)
        {
            ByteArray byteArray = new ByteArray(bytes);
            int opcode = byteArray.ReadInt();
            if (!mgr.methodMap.ContainsKey(opcode))
            {
                Debug.Log("opcode:" + opcode + "未注册");
            }
            else {
                MethodInfo method = mgr.methodMap[opcode];
                object[] param = { byteArray };
                method.Invoke(null, param);
            }
        }
    }
    void OnDestroy()
    {
        SocketHelper.GetInstance().Closed();
    }
}

